import router from "./router";
import store from "./store";
const whiteList = ['/login', '/404']
// 全局前置守卫
router.beforeEach((to, from, next) => {
  // to:跳转到路由对象
  // from:从哪里来
  // next:放行next() 
  const token = store.state.user.token
  if (token) {
    // 有token
    if (to.path === '/login') {
      next('/')
    } else {
      next()
    }
  } else {
    // 没有token
    if (whiteList.includes(to.path)) {
      next()
    } else {
      next('/login')
    }
  }
  next()
})